package com.edu.exam.enums;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 扫描仪连接状态枚举
 *
 * @author System
 * @version 1.0.0
 */
public enum ScannerConnectionStatus implements BaseEnum {
    CONNECTED("connected", "已连接"),
    DISCONNECTED("disconnected", "已断开"),
    CONNECTING("connecting", "连接中"),
    ERROR("error", "错误"),
    MAINTENANCE("maintenance", "维护中"),
    UNKNOWN("unknown", "未知");

    private final String code;
    private final String description;

    ScannerConnectionStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据代码查找枚举值
     *
     * @param code 枚举代码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果代码不存在
     */
    public static ScannerConnectionStatus fromCode(String code) {
        for (ScannerConnectionStatus status : ScannerConnectionStatus.values()) {
            if (status.code.equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown scanner connection status code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 枚举描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述不存在
     */
    public static ScannerConnectionStatus fromDescription(String description) {
        for (ScannerConnectionStatus status : ScannerConnectionStatus.values()) {
            if (status.description.equals(description)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown scanner connection status description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}
